{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " ...\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]]\n",
      "数组是否全零: False\n",
      "2\n",
      "非零元素的索引：\n",
      "维度 0 的非零索引: [ 10  10  10 ... 477 477 477]\n",
      "维度 1 的非零索引: [382 383 384 ... 634 635 636]\n"
     ]
    }
   ],
   "source": [
    "# 检查一下解包之后的depth 因为看起来好像全黑 \n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "\n",
    "# 用图片的路径替换 'path/to/your/image.png'\n",
    "image_path = '/Users/liangchen/myDoc/scene0000_00/scene_open/depth/0.png'\n",
    "image = Image.open(image_path)\n",
    "\n",
    "# 将图像转换为 NumPy 数组\n",
    "image_array = 30*np.array(image)\n",
    "\n",
    "print(image_array)\n",
    "\n",
    "# 检查数组是否全零\n",
    "is_all_zero = np.all(image_array == 0)\n",
    "\n",
    "print(f\"数组是否全零: {is_all_zero}\")\n",
    "\n",
    "# 找到非零元素的索引\n",
    "nonzero_indices = np.nonzero(image_array)\n",
    "print(len(nonzero_indices))\n",
    "# 打印非零元素的索引\n",
    "print(\"非零元素的索引：\")\n",
    "for dim in range(len(nonzero_indices)):\n",
    "    print(f\"维度 {dim} 的非零索引: {nonzero_indices[dim]}\")\n",
    "\n",
    "image = Image.fromarray(image_array)\n",
    "\n",
    "# 保存 Image 对象为 PNG 图片\n",
    "image.save('/Users/liangchen/myDoc/scene0000_00/scene_open/depth/output.png')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
